package kz.pompei.ifacer.util;

import javax.swing.SwingUtilities;

public class HandlerList extends KillingList<Handler> {
  public void fire() {
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        try {
          for (Handler h : HandlerList.this) {
            h.handle();
          }
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      }
    });
  }
  
  private Handler handler = null;
  
  public Handler handler() {
    if (handler == null) handler = new Handler() {
      @Override
      public void handle() throws Exception {
        fire();
      }
    };
    return handler;
  }
}
